module.exports = () => async (ctx, next) => {
  try {
    const token = ctx.header.authorization;
    if (token) {
      verity(token); // verify 函数验证token,并获取相关信息
    }
    await next();
  } catch (error) {
    console.log(error);
  }
};

// app.js
const Koa = require('koa');
const app = new Koa();
const token = require('./middleware/token');
app.use(token());
app.listen(3000, () => {
  console.log('server is running at http://localhost:3000');
});
